package com.jeework.modules.sys.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeework.common.config.Global;
import com.jeework.common.entity.Page;
import com.jeework.common.utils.PageUtil;
import com.jeework.common.utils.StringUtils;
import com.jeework.modules.sys.entity.DictType;
import com.jeework.modules.sys.entity.User;
import com.jeework.modules.sys.service.DictService;
import com.jeework.modules.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Controller
public class SysController {

    @Autowired
    private UserService userService;

    @Autowired
    private DictService dictService;

    @RequestMapping("/sysLogin")
    public String sysLogin(Map<String, Object> map) {

        return "/sysLogin";
    }

    @RequestMapping("/a/login")
    public String doLogin(String username, String password, Map<String, Object> map) {
        String pass_word = "e3c3bb4e292348d09ec4643c087d40a433728ca057e7266bae63195d";
        String user_name = "system";
        User user = userService.doLogin(user_name, pass_word);
        if (null != user) {
            return "/sysIndex";
        }
        return "/sysLogin";
    }

    public Model menuList(Model model) {

        return model;
    }

    @RequestMapping("/a/sys/dict/list")
    public String dictList(DictType dictType, Map<String, Object> map) {
       return "/sys/sysDictList";
    }

    @RequestMapping("/a/sys/dict/listData")
    @ResponseBody
    public Page<DictType> dictListData(HttpServletRequest request,DictType dictType, Map<String, Object> map) {
        Page<DictType> page=new Page<DictType>(request);
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        List<DictType> list = dictService.doList(dictType);
        PageInfo pageInfo = new PageInfo(list);
        PageUtil.transferPage(page, pageInfo);
        return page;
    }


}
